﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Json;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using ThaireInvestmentWeb.ReportServiceRef;
/*
 
Company:		=> COMPANY
Financial Instrument :	=> Fixed Valued
Asset Class :	=> Fixed Valued depend on Financial Instrument
Issuer :		=> ISSUER
Keep at :		=> Fixed Valued
Time to Maturity : 	=> Fixed Valued
After Matured :	=> Fixed Valued	 
Status :	  	=> Fixed Valued
Related / Non Related : => Fixed Valued
 * 
 */
namespace ThaireInvestmentWeb.Controllers.Master
{
    public class MasterController : Controller
    {
        //
        // GET: /Master/

        public ActionResult Index()
        {
            return View();
        }
        public JsonResult GetYears()
        {
            JsonArrayCollection array = new JsonArrayCollection();



            int minyear = int.Parse(WebConfigurationManager.AppSettings["MinYear"]);
            int maxyear = int.Parse(WebConfigurationManager.AppSettings["MaxYear"]);

             for (int i = minyear; i <= maxyear;i++ )
             {
                 JsonObjectCollection obj1 = new JsonObjectCollection();
                 obj1.Add(new JsonStringValue("key", i.ToString()));
                 obj1.Add(new JsonStringValue("val", (i+543).ToString()));
                 array.Add(obj1);
             }
            return Json(array.ToString(), JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetCompanyType(string type)
        {
            JsonArrayCollection array = new JsonArrayCollection();



            ReportServiceClient client =
                new ReportServiceClient();
            KeyValueDTO[] arrays = client.GetMasterMode("company",type);
            foreach (KeyValueDTO kv in arrays)
            {
                JsonObjectCollection obj1 = new JsonObjectCollection();
                obj1.Add(new JsonStringValue("key", kv.Keyid.ToString()));
                obj1.Add(new JsonStringValue("val", kv.Val));
                array.Add(obj1);
            }
            return Json(array.ToString(), JsonRequestBehavior.AllowGet);

        }
        public JsonResult GetCompany()
        {
            JsonArrayCollection array = new JsonArrayCollection();
     
          

            ReportServiceClient client =
                new  ReportServiceClient();
            KeyValueDTO[] arrays = client.GetMaster("company");
            foreach (KeyValueDTO kv in arrays)
            {
                JsonObjectCollection obj1 = new JsonObjectCollection();
                obj1.Add(new JsonStringValue("key", kv.Keyid.ToString()));
                obj1.Add(new JsonStringValue("val", kv.Val));
                array.Add(obj1);
            }
            return Json(array.ToString(), JsonRequestBehavior.AllowGet);

        }

        public JsonResult GetIssuer()
        {
            JsonArrayCollection array = new JsonArrayCollection();



            ReportServiceClient client =
                new ReportServiceClient();
            KeyValueDTO[] arrays = client.GetMaster("issuer");
            foreach (KeyValueDTO kv in arrays)
            {
                JsonObjectCollection obj1 = new JsonObjectCollection();
                obj1.Add(new JsonStringValue("key", kv.Keyid.ToString()));
                obj1.Add(new JsonStringValue("val", kv.Val));
                array.Add(obj1);
            }
            return Json(array.ToString(), JsonRequestBehavior.AllowGet);

        }
    }
}
